package zhh.tangbao.auxiliary.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhh.tangbao.auxiliary.dto.notice.NoticeQueryDto;
import zhh.tangbao.auxiliary.entity.SystemNotice;
import zhh.tangbao.auxiliary.service.SystemNoticeService;
import zhh.tangbao.system.annotation.Authority;
import zhh.tangbao.system.annotation.Log;
import zhh.tangbao.system.constant.AuthorityModel;
import zhh.tangbao.system.result.Result;

/**
 * 2023/2/26
 * @author 粥灰灰
 * @version 1.0
 * 描述
 */

@RestController
@RequestMapping("/api/notice")
public class SystemNoticeController {

    @Autowired
    private SystemNoticeService service;

    @PostMapping("/release")
    @Authority(authorities = "notice", authorityModel = AuthorityModel.CONTAIN)
    @Log(function = "发布公告", moduleName = "公告管理")
    public Result releaseNotice(@RequestBody SystemNotice systemNotice) {
        return Result.successOrFail(service.releaseSystemNotice(systemNotice));
    }

    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") String id) {
        SystemNotice notice = service.get(id);
        return Result.success().put(notice);
    }

    @GetMapping("/page")
    public Result page(NoticeQueryDto dto) {
        return Result.success().put(service.page(dto));
    }

    @DeleteMapping("/delete/{id}")
    @Authority(authorities = "notice", authorityModel = AuthorityModel.CONTAIN)
    @Log(function = "删除公告", moduleName = "公告管理")
    public Result delete(@PathVariable("id") String id) {
        return Result.successOrFail(service.delete(id));
    }

}
